﻿using Microsoft.AspNetCore.SignalR;
using System;
using System.Threading.Tasks;

namespace Longbow.Web.SignalR
{
    /// <summary>
    /// 异常 SingalR 通知类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    internal class SignalRExceptionFilterHandler<T> : ISignalRExceptionFilterHandler<T> where T : Hub
    {
        private readonly Func<IHubContext<T>, Exception, Task> _handler;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="handler"></param>
        public SignalRExceptionFilterHandler(Func<IHubContext<T>, Exception, Task> handler) => _handler = handler;

        /// <summary>
        /// 消息通知方法
        /// </summary>
        /// <param name="hub"></param>
        /// <param name="ex"></param>
        public Task SendAsync(IHubContext<T> hub, Exception ex) => _handler.Invoke(hub, ex);
    }
}
